#include "main.h"
extern struct contact_link*P;
extern int state[100];
void*client_read(void*argv)
{
    //printf("读线程创建成功\n");
    int C=*(int*)argv;
    //printf("描述符=%d\n",C);
    struct tcp_data from_buf={0};
    while(1)
    {
        memset(&from_buf,0,sizeof(from_buf));
        //printf("阻塞接收消息\n");
        //阻塞接收消息
        int ret=read(C,&from_buf,28);
        //printf("读消息ret=%d,类型:%d\n",ret,from_buf.type);
        //判断消息类型
        if     (ret!=0 && from_buf.type>=1000 && from_buf.type<2000)
        {
            update_contact(C,&from_buf,P);
        }
        else if(ret!=0 && from_buf.type>=2000 && from_buf.type<3000)
        {
            if(from_buf.type==2999)
            {
                state[2]=2999;
                continue;
            }
            read(C,&from_buf.buf,from_buf.size);
            printf("%s\n",from_buf.buf);
                      
        }
        else if(0==ret)
        {
            //printf("服务器掉线\n");
            // system("./client  1");
            // kill(state[0],9);
        }
    }
    return NULL;
}